/********************************************************************
This file is part of the KDE project.

Copyright (C) 2014 Martin Gräßlin <mgraesslin@kde.org>
Copyright (C) 2014 Kai Uwe Broulik <kde@privat.broulik.de>

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*********************************************************************/
import QtQuick 2.4
import QtQuick.Layouts 1.1
import QtQuick.Controls 2.2
import org.kde.plasma.plasmoid 2.0
import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.components 2.0 as PlasmaComponents
import org.kde.plasma.extras 2.0 as PlasmaExtras

Item {
        
    property alias text: filter.text

    RowLayout {
        id: rl
        anchors.top: parent.top
        
        anchors.left: parent.left
        anchors.right: parent.right

        PlasmaComponents.TextField {
            id: filter
            placeholderText: i18n("Search")
            Layout.fillWidth: true
            clearButtonShown: true
            onEditingFinished: {
                query(filter.text);
            }
        }
        PlasmaComponents.ToolButton {
            iconSource: "search"
            tooltip: i18n("Search")
            onClicked: {
                query(filter.text)
            }
        }
    }
    PlasmaExtras.ScrollArea {
        anchors.top: rl.bottom
        anchors.left: rl.left
        anchors.bottom: parent.bottom
        anchors.right: rl.right
        TextEdit {
            id: textEdit
            width: rl.width
            color: "white"
            textFormat: Text.RichText
            selectByMouse: true
            wrapMode: TextEdit.Wrap
            cursorVisible: false
            
            onLinkActivated: Qt.openUrlExternally(link)
        }

    }
    YOUDAO {//NetEase YOUDAO Dictionary&Translate
        id: yd;
        onDataReady:{
            textEdit.text = data
        }
    }
    
    function query(word){
        yd.queryYD(word);
    }
}
